<?php
try {
	require_once('TCPDF/config/lang/ger.php');
	require_once('TCPDF/tcpdf.php');
} catch (Exception $e) {
	die("Fehler: TCPDF Library nicht gefunden!");
}

// Extend the TCPDF class to create custom Header and Footer
class Ht_Pdf extends TCPDF {

	public function setupPDF() {
		
		// set default font subsetting mode
		$this->setFontSubsetting(true);
		
		return $this;
		
	}
	public function invoiceHeaderFooter() {
		
		//Settings-object
		$settings = new Model_Settings();
		
		// set document information
		$this->SetCreator(PDF_CREATOR);
		$this->SetAuthor($settings->getValueByName('company_name'));
		$this->SetTitle('Rechnung #'.$settings->getValueByName('current_invoice_number'));
		$this->SetSubject('Rechnung #'.$settings->getValueByName('current_invoice_number'));
		$this->SetKeywords('');
		
		// set default header data
		//$this->SetHeaderData('../../../public'.$settings->getValueByName('company_logo'), 50, 'Rechnung #'.$settings->getValueByName('current_invoice_number'), $settings->getValueByName('company_name'));
		//Sonderwunsch Rafael
		$this->SetHeaderData('../../../public'.$settings->getValueByName('company_logo'), 50, '', '');
		
		// set header and footer fonts
		$this->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
		$this->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
		
		// set default monospaced font
		$this->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
		
		//set margins
		//Abstand links nach Din = 20mm
		$margin_left = 20;
		$this->SetMargins($margin_left, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
		$this->SetHeaderMargin(PDF_MARGIN_HEADER);
		$this->SetFooterMargin(PDF_MARGIN_FOOTER);
		
		//set auto page breaks
		$this->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
		
	}
	// Page footer
    public function Footer() {
        
    	//Settingsobjekt
    	$s = new Model_Settings();   	
		//Footer setzt 35mm über dem Boden an
        $this->SetY(-40);
		
        //Einstellungen Footertabelle
        $w_tablefield = 50;
        $border = 0;
        $fields_bgcolor = false;
        $line_height = 4;
        //Footertabelle
        //Tabellenheader
        $this->SetFont('helvetica', 'B', 7);
        $this->MultiCell($w_tablefield, 0, "Anschrift", $border, 'L', $fields_bgcolor, 0);
        $this->MultiCell($w_tablefield, 0, "Kontakt", $border, 'L', $fields_bgcolor, 0);
        $this->MultiCell($w_tablefield, 0, "Bankverbindung", $border, 'L', $fields_bgcolor, 0);
        //Unterscheidung ob Steuernummer oder USt-ID
        $tax_desc = ($s->getValueByName('company_taxID') != "") ? 'Ust. ID-Nummer' : 'Steuernummer';
        $this->MultiCell($w_tablefield, 0, $tax_desc, $border, 'L', $fields_bgcolor, 0);
        $this->Ln($line_height);
        //1. Zeile
        $this->SetFont('helvetica', '', 7);
        $this->MultiCell($w_tablefield, 0, $s->getValueByName('company_name'), $border, 'L', $fields_bgcolor, 0);
        $this->MultiCell($w_tablefield, 0, "Fon: ".$s->getValueByName('company_phone_landline'), $border, 'L', $fields_bgcolor, 0);
        $this->MultiCell($w_tablefield, 0, $s->getValueByName('company_bank_name'), $border, 'L', $fields_bgcolor, 0);
        //Steuernummer bzw. ID
        $tax_number = ($s->getValueByName('company_taxID') != "") ? $s->getValueByName('company_taxID') : $s->getValueByName('company_taxnumber');
        $this->MultiCell($w_tablefield, 0, $tax_number, $border, 'L', $fields_bgcolor, 0);
        $this->Ln($line_height);
        //2. Zeile
        $this->MultiCell($w_tablefield, 0, $s->getValueByName('company_additionalinfo'), $border, 'L', $fields_bgcolor, 0);
        $this->MultiCell($w_tablefield, 0, "Fax: ".$s->getValueByName('company_fax'), $border, 'L', $fields_bgcolor, 0);
        $this->MultiCell($w_tablefield, 0, "Kontonr.: ".$s->getValueByName('company_bank_accountnumber'), $border, 'L', $fields_bgcolor, 0);
        $this->MultiCell($w_tablefield, 0, '', $border, 'L', $fields_bgcolor, 0);
        $this->Ln($line_height);
        //3. Zeile
        $this->MultiCell($w_tablefield, 0, $s->getValueByName('company_streetaddress'), $border, 'L', $fields_bgcolor, 0);
        $this->MultiCell($w_tablefield, 0, "Mail: ".$s->getValueByName('company_mail'), $border, 'L', $fields_bgcolor, 0);
        $this->MultiCell($w_tablefield, 0, "BLZ: ".$s->getValueByName('company_bank_code'), $border, 'L', $fields_bgcolor, 0);
        $this->MultiCell($w_tablefield, 0, '', $border, 'L', $fields_bgcolor, 0);
        $this->Ln($line_height);
        //4. Zeile
        $this->MultiCell($w_tablefield, 0, $s->getValueByName('company_zipcode')." ".$s->getValueByName('company_city'), $border, 'L', $fields_bgcolor, 0);
        $this->Ln($line_height);
        //Seitenzahl
        $this->SetFont('helvetica', 'I', 7);
        $this->Cell(0, 10, 'Seite '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
    }
}
?>